<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="layui-form-item">
                <!-- 设备编hao -->
                <label for="eno" class="layui-form-label">
                    <span class="x-red">*</span>设备编码</label>
                <div class="layui-input-inline">
                    <input type="text" id="eno" readonly name="eno" required="" lay-verify="required" autocomplete="off"
                           class="layui-input"></div>
            </div>

            <input type="hidden" name="equipmentId" id="equipmentId"/>

            <div class="layui-form-item">
                <label class="layui-form-label"> <span
                        class="x-red"></span>设备图片
                </label>
                <div class="layui-input-inline">
                    <div class="layui-upload">
                        <button type="button" class="layui-btn layui-btn-normal" id="test1">选择文件</button>
                        <div class="layui-upload-list">
                            <img class="layui-upload-img" id="demo1" width="200px" height="150px">
                        </div>
                    </div>
                    <input type="hidden" id="url" name="url"
                           lay-verify="id_fan" autocomplete="off" class="layui-input">
                </div>
            </div>
           <!-- <div class="layui-upload">
                <label for="eno" class="layui-form-label">
                    <span class="x-red">*</span>设备图片</label>
                <button type="button" class="layui-btn" id="test1">上传图片</button>
                <div class="layui-upload-list">
                    <img class="layui-upload-img" id="demo1" style="width: 100px;height: 100px">
                    <p id="demoText"></p>
                </div>
            </div>-->
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <button class="layui-btn" lay-filter="add" lay-submit="" id="add">增加</button>
            </div>
        </form>
    </div>
</div>

<script>
    layui.use(['upload','form'], function(){
        var $ = layui.jquery
            ,form = layui.form
            ,upload = layui.upload;

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            ,url: 'addpic'
            ,accept: 'images'
            ,acceptMime: 'image/*'
            ,size: '1024*5'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(json){
                //如果上传失败
                if(json.code == 0){
                    $("#url").prop("value",json.msg);
                    form.render();
                }
                //上传成功
                if(json.code > 0){
                    return layer.msg('上传失败');
                }
            }
        });
    });
</script>

<script>layui.use(['form', 'layer',  'jquery'], function () {
    var $ = layui.jquery,
        form = layui.form,
        layer = layui.layer;
    var equipmentId = window.location.search.substring(1);
    $("#equipmentId").val(equipmentId);

    $.get("equipmentGet", {id: equipmentId}, function (p) {
        $("#eno").prop("value", p.data.eno)
    })

    $.get("getEquipmentPic", {id: equipmentId}, function (p) {
        if (p.code == 0) {
            $('#demo1').prop('src',  p.data.url);
        }
    })

   /* upload.render({
        elem: '#test',
        url: 'upload',
        choose: function (obj) {
            obj.preview(function (index, file, result) {
                $('#demo').prop('src', result);
            });
        },
        done: function (res) {
            $("#url").prop("value", res.msg);
        }
    });*/

    form.on('submit(add)',
        function (data) {
            $.get("addEQPic", data.field, function (p) {
                if (p.code == 0) {
                    layer.open({
                        icon: 5,
                        content: p.msg,
                        time: 3
                    })
                    xadmin.close();
                }
                alert(p.msg);
            })
            return false;
        })
});
</script>

</body>

</html>